/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lt.ntec.danblog.client.utils;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.VerticalPanel;
import lt.ntec.danblog.client.utils.panels.UtilityPanel;
import lt.ntec.danblog.shared.utils.text.*;

/**
 *
 * @author Tadas
 */
class MenuPanel extends VerticalPanel {
    public static final String CAMEL__CASE = "Camel Case";
    public static final String DECODE__BASE64 = "Decode Base64";
    public static final String ENCODE__BASE64 = "Encode Base64";
    public static final String LOWER_CASE = "lower case";
    public static final String M_D5__HASH = "MD5 Hash";
    public static final String UPPE_R_CASE = "UPPER CASE";

    private UtilityPanel utilityPanel;

    public MenuPanel(UtilityPanel utilityPanel) {
        super();
        this.utilityPanel = utilityPanel;
        
        Tree tree = new Tree();
        
        TreeItem root = new TreeItem("Text");
        
        
        tree.addItem(root);
        tree.setTitle("Utils");
        
        Anchor anchor = new Anchor(DECODE__BASE64);
        anchor.addClickHandler(new DecodeBase64ClickHandler());
        root.addItem(anchor);


        Anchor anchor1 =
                new Anchor(ENCODE__BASE64);
        anchor1.addClickHandler(new EncodeBase64ClickHandler());
        root.addItem(anchor1);

        Anchor anchor2 = new Anchor(UPPE_R_CASE);
        anchor2.addClickHandler(new UpperCaseClickHandler());
        root.addItem(anchor2);

        Anchor anchor3 = new Anchor(CAMEL__CASE);
        anchor3.addClickHandler(new CamelCaseClickHandler());
        root.addItem(anchor3);

        Anchor anchor4 = new Anchor(LOWER_CASE);
        anchor4.addClickHandler(new LowerCaseClickHandler());
        root.addItem(anchor4);

        Anchor anchor5 = new Anchor(M_D5__HASH);
        anchor5.addClickHandler(new Md5HashClickHandler());
        root.addItem(anchor5);

        setStylePrimaryName("utils-panel-menu");
        setWidth("100%");
        
        root.setState(true);
        tree.ensureSelectedItemVisible();
        add(tree);
    }

    private class DecodeBase64ClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            utilityPanel.setUtility(new DecodeBase64());
            utilityPanel.getLabel().setText(DECODE__BASE64);
        }
    }

    private class EncodeBase64ClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            utilityPanel.setUtility(new EncodeBase64());
            utilityPanel.getLabel().setText(ENCODE__BASE64);
        }
    }

    private class UpperCaseClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            utilityPanel.setUtility(new UpperCaseUtility());
            utilityPanel.getLabel().setText(UPPE_R_CASE);
        }
    }

    private class LowerCaseClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            utilityPanel.setUtility(new LowerCaseUtility());
            utilityPanel.getLabel().setText(LOWER_CASE);
        }
    }

    private class CamelCaseClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            utilityPanel.setUtility(new CamelCaseUtility());
            utilityPanel.getLabel().setText(CAMEL__CASE);
        }
    }

    private class Md5HashClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            utilityPanel.setUtility(new Md5Utility());
            utilityPanel.getLabel().setText(M_D5__HASH);
        }
    }
}
